#pragma once
#include <cstdint>
#include <thread>

#ifdef __linux__
#include <syscall.h>
#include <unistd.h>
#elif _WIN32
#include <windows.h>
#endif

namespace axon_logger {
namespace utils {
namespace context {
    
    // 高效获取缓存的线程ID
    inline uint64_t get_thread_id() noexcept {
    #ifdef __linux__
        // 在Linux上，syscall(SYS_gettid)是获取真实线程ID的最快方式
        static thread_local const uint64_t tid = static_cast<uint64_t>(syscall(SYS_gettid));
    #elif _WIN32
        static thread_local const uint64_t tid = static_cast<uint64_t>(GetCurrentThreadId());
    #else
        // 为其他平台提供一个可移植的备选方案
        static thread_local const uint64_t tid = std::hash<std::thread::id>{}(std::this_thread::get_id());
    #endif
        return tid;
    }

}  // namespace context
}  // namespace utils
}  // namespace axon_logger

